package com.budwk.app.sqfwV2.service.mine;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.exception.ServiceException;
import com.budwk.app.sqfw.constants.SqfwFormSummaryConstants;
import com.budwk.app.sqfw.controllers.admin.customservice.CenturyCitySecurityForAdminController;
import com.budwk.app.sqfw.enums.StreetEnum;
import com.budwk.app.sqfw.enums.SupportBusinessTypeEnum;
import com.budwk.app.sqfw.models.Sqfw_WorkSummary;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.SqfwWorkSummaryService;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwV2.dto.CaringStaffDTO;
import com.budwk.app.sqfwV2.dto.WorkSummaryDTO;
import com.budwk.app.sqfwV2.dto.centuryCity.CenturyCityOldCarePdfDTO;
import com.budwk.app.sqfwV2.dto.dto.FireSafetyOnDayingRoadPdfDTO;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskPdfDTO;
import com.budwk.app.sqfwV2.dto.dto.childrenVisits.ChildrenVisitationPdfDTO;
import com.budwk.app.sqfwV2.dto.dulaying.DuLaYingPropagandaOrScreeningPdfDTO;
import com.budwk.app.sqfwV2.dto.dulaying.ScreeningHiddenDTO;
import com.budwk.app.sqfwV2.dto.povertyMonitoring.PovertyAlleviationDTO;
import com.budwk.app.sqfwV2.dto.publicSecurity.PublicSecurityDTO;
import com.budwk.app.sqfwV2.dto.shawenTown.ShawenTownSafetyPdfDTO;
import com.budwk.app.sqfwV2.enums.PropagandaOrScreeningEnum;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.starter.common.result.Result;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import org.apache.commons.lang3.StringUtils;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import java.util.*;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.generateWordDocument;

/**
 * 个人工作总结
 * @BelongsProject: dfxy-shequ
 * @Author: yangweimin
 * @CreateTime: 2024-06-18  13:53
 * @Description: TODO
 */
@IocBean
public class WorkSummaryService {
    @Inject
    private SqfwFormsummaryNewService formsummaryNewService;
    @Inject
    private CenturyCitySecurityForAdminController centuryCitySecurityForAdminController;
    @Inject
    private SqfwWorkSummaryService sqfwWorkSummaryService;
    @Inject
    private SysUserService sysUserService;

    public void update(List<Sqfw_WorkSummary> workSummaryList, List<String> idList) {
        String url = downWord(workSummaryList);
        for (Sqfw_WorkSummary workSummary : workSummaryList) {
            workSummary.setUrl(url);
        }
        sqfwWorkSummaryService.update(workSummaryList, idList);
    }

    /**
     * 下载pdf
     * @return
     */
    public String downWord(List<Sqfw_WorkSummary> workSummaryList) {
        StringBuilder text = new StringBuilder();
        for (Sqfw_WorkSummary sqfwWorkSummary : workSummaryList) {
            text.append(sqfwWorkSummary.getText());
        }
        String fileName = "个人工作总结";
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("text", text);
        List<NiceXWPFDocument> xwpfDocumentList = new ArrayList<>();
        XWPFTemplate xwpfTemplate = generateWordDocument(dataMap, null, null, "workSummary.docx");
        xwpfDocumentList.add(xwpfTemplate.getXWPFDocument());
        GenerateWordAndPdfUrlVO vo = CommonFormOfficeUtils.wordUpload(xwpfDocumentList, fileName);
        String url = vo.getFileName();
        if (!url.startsWith("/")) url = "/" + url;
        return url;
    }

    /**
     * 如果start不为null,则执行的是指定时间的任务，如果为空，则执行前一天的任务
     * @param start
     * @param end
     */
    public void everyday(String start, String end) {
        Date time = DateUtil.parse(DateUtil.format(new Date(),"yyyy-MM-dd"));
        // 减1天
        Date startTime = DateUtil.offsetDay(time, -1);

        Date endTime = time;

        Cnd cnd = Cnd.NEW();
        if (StringUtils.isNotBlank(start)) {
            try {
                DateUtil.parse(start, "yyyy-MM-dd"); // 验证日期格式。
            } catch (Exception e) {
                throw new ServiceException("日期格式不正确");
            }
            cnd.and(Sqfw_formSummary_new::getFillDate, ">=", DateUtil.parse(start,"yyyy-MM-dd"));
            if (StringUtils.isNotBlank(end)) {
                try {
                    DateUtil.parse(end, "yyyy-MM-dd"); // 验证日期格式。
                } catch (Exception e) {
                    throw new ServiceException("日期格式不正确");
                }
                cnd.and(Sqfw_formSummary_new::getFillDate, "<", DateUtil.parse(end,"yyyy-MM-dd"));
            }
        } else {
            cnd.and(Sqfw_formSummary_new::getFillDate, ">=", startTime);
            cnd.and(Sqfw_formSummary_new::getFillDate, "<", endTime);
        }
        cnd.asc(Sqfw_formSummary_new::getFillDate);
        List<Sqfw_formSummary_new> formSummaryNewList = formsummaryNewService.query(cnd);

        inspectionStatistics(formSummaryNewList);
    }

    /**
     * 执行所有时间任务
     */
    public void all() {
        Date time = DateUtil.parse("2023-06-01","yyyy-MM-dd");

        while (time.getTime() <= DateUtil.parse(DateUtil.format(new Date(),"yyyy-MM-dd")).getTime()) {
            // 减1天
            Date startTime = DateUtil.offsetDay(time, -1);

            Date endTime = time;

            Cnd cnd = Cnd.NEW();
            cnd.and(Sqfw_formSummary_new::getFillDate, ">=", startTime);
            cnd.and(Sqfw_formSummary_new::getFillDate, "<", endTime);
            cnd.asc(Sqfw_formSummary_new::getFillDate);

            List<Sqfw_formSummary_new> formSummaryNewList = formsummaryNewService.query(cnd);

            inspectionStatistics(formSummaryNewList);

            time = DateUtil.offsetDay(time, 1);
        }
    }

    /**
     * 巡查统计
     * @return
     */
    @Aop(TransAop.READ_COMMITTED)
    public void inspectionStatistics(List<Sqfw_formSummary_new> formSummaryNewList) {
        if (formSummaryNewList.size() == 0) {return;}

        Set<String> typeSet = new HashSet<>();
        Set<String> userSet = new HashSet<>();
        for (Sqfw_formSummary_new formSummaryNew : formSummaryNewList) {
            typeSet.add(formSummaryNew.getType());
            userSet.add(formSummaryNew.getCreateBy());
        }

        for (String userId : userSet) {
            sqfwWorkSummaryService.delete(userId, DateUtil.parse(DateUtil.format(formSummaryNewList.get(0).getFillDate(), "yyyy-MM-dd")));

            Sys_user user = null;
            try {
                user = sysUserService.getUserById(userId);
            } catch (Exception e) {
                continue;
            }

            List<Sqfw_formSummary_new> formSummaryList = new ArrayList<>();
            for (Sqfw_formSummary_new formSummaryNew : formSummaryNewList) {
                if (user.getId().equals(formSummaryNew.getCreateBy())) {
                    formSummaryList.add(formSummaryNew);
                }
            }

            List<Sqfw_WorkSummary> workSummaryList = new ArrayList<>();

            int i = 1;
            Date fillDate = null;
            for (String type : typeSet) {
                Sqfw_WorkSummary workSummary = new Sqfw_WorkSummary();
                WorkSummaryDTO dto = typeStatistics(type, formSummaryList);
                List<WorkSummaryDTO.Place> placeList = dto.getList();
                if (dto.getTotal() == 0 || placeList.size() == 0) {continue;}
                Date date = placeList.get(0).getFillDate();
                fillDate = DateUtil.parse(DateUtil.format(date, "yyyy-MM-dd"));
                workSummary.setUserId(user.getId());
                workSummary.setUserName(user.getUsername());
                workSummary.setType(type);
                workSummary.setIndex(i);
                workSummary.setFillDate(fillDate);
                if (SqfwFormSummaryConstants.safety_check.equals(type) ||
                        SupportBusinessTypeEnum.BATYUN_SAFE.getName().equals(type) ||
                        SupportBusinessTypeEnum.SAFE_CHECK.getName().equals(type)) {
                    workSummary.setText(getSafetyCheckText(dto, user));
                }
                if (SqfwFormSummaryConstants.public_security.equals(type)) {
                    workSummary.setText(getSocialSecurityText(dto, user));
                }
                if ((SupportBusinessTypeEnum.PROPAGANDA_OF_SAFE_CONSTRUCTION.getName().equals(type) ||
                        SqfwFormSummaryConstants.propaganda_screening.equals(type))) {
                    workSummary.setText(getPropagateCheckText(dto, user));
                }
                if ((SupportBusinessTypeEnum.OLD_CARE_SERVICE.getName().equals(type))) {
                    workSummary.setText(getYLFWText(dto, user));
                }
                if ((SupportBusinessTypeEnum.CARE_WORKER_VISIT.getName().equals(type))) {
                    workSummary.setText(getGARYTFext(dto, user));
                }
                if (SupportBusinessTypeEnum.CHILDREN_VISITATION.getName().equals(type)) {
                    workSummary.setText(getETTFext(dto, user));
                }
                if (SupportBusinessTypeEnum.POVERTY_MONITORING.getName().equals(type)) {
                    workSummary.setText(getTPText(dto, user));
                }
                workSummary.setCreateDate(new Date());
                workSummary.setUpdateDate(new Date());

                sqfwWorkSummaryService.insert(workSummary);

                workSummaryList.add(workSummary);
                i ++;
            }

            String url = downWord(workSummaryList);
            sqfwWorkSummaryService.update(userId, fillDate, url);
        }
    }

    /**
     * 安全排查总结
     * @param dto
     * @param user
     * @return
     */
    public String getSafetyCheckText(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个巡查对象进行了安全排查整治。其中：无隐患"+dto.getNoHiddenNum()+"家，有隐患"+dto.getIsHiddenNum()+"家。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" "+ place.getName() + "，法人"+place.getLegalPerson()+"，问题："+place.getHidden()+"\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 社会治安总结
     * @param dto
     * @param user
     * @return
     */
    public String getSocialSecurityText(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个巡查对象进行了社会治安重点场所巡查。其中：无隐患"+dto.getNoHiddenNum()+"家，有隐患"+dto.getIsHiddenNum()+"家。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" "+ place.getName() + "，法人"+place.getLegalPerson()+"，问题："+place.getHidden()+"\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 宣传/排查
     * @param dto
     * @param user
     * @return
     */
    public String getPropagateCheckText(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个巡查对象进行了平安宣传。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            if (PropagandaOrScreeningEnum.PROPAGANDA.getName().equals(place.getType())) {
                String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
                stringBuilder.append(date +" 在"+place.getName()+"进行了"+place.getTheme()+"宣传\n");
            }
            if (PropagandaOrScreeningEnum.SCREENING.getName().equals(place.getType())) {
                String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
                stringBuilder.append(date +" 在"+place.getName()+"进行了"+place.getTheme()+"排查，问题："+place.getHidden()+"\n");
            }
        }
        return stringBuilder.toString();
    }

    /**
     * 养老服务站巡查
     * @param dto
     * @param user
     * @return
     */
    public String getYLFWText(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个养老服务站进行了巡查。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" 在"+place.getName()+"进行了巡查\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 关爱人员探访
     * @param dto
     * @param user
     * @return
     */
    public String getGARYTFext(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个关爱人员进行探访。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" 在"+place.getName()+"进行了"+place.getType()+"走访\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 儿童探访
     * @param dto
     * @param user
     * @return
     */
    public String getETTFext(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"名儿童进行了探访。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" 对"+place.getType()+place.getName() +"进行了探访\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 脱贫检测
     * @param dto
     * @param user
     * @return
     */
    public String getTPText(WorkSummaryDTO dto, Sys_user user) {
        StringBuilder stringBuilder = new StringBuilder();
        List<WorkSummaryDTO.Place> list = dto.getList();
        String time = DateUtil.format(list.get(0).getFillDate(), "yyyy年MM月dd");
        stringBuilder.append(user.getUsername()+"在"+time+"日对"+dto.getTotal()+"个脱贫家庭进行了入户。详情如下：\n");
        for (WorkSummaryDTO.Place place : list) {
            String date = DateUtil.format(place.getFillDate(), "yyyy-MM-dd HH:mm:ss");
            stringBuilder.append(date +" 对"+place.getName() +"家进行了入户调查\n");
        }
        return stringBuilder.toString();
    }

    /**
     * 安类型统计
     * @param type
     * @param formSummaryNewList
     * @return
     */
    private WorkSummaryDTO typeStatistics(String type, List<Sqfw_formSummary_new> formSummaryNewList) {
        int total = 0;
        int isHiddenNum = 0;
        int noHiddenNum = 0;
        WorkSummaryDTO dto = new WorkSummaryDTO();
        List<WorkSummaryDTO.Place> list = new ArrayList<>();

        for (Sqfw_formSummary_new formSummaryNew : formSummaryNewList) {
            if (StringUtils.isBlank(formSummaryNew.getUnitName())) continue;

            // 大营路和南明区-安全排查
            if ((formSummaryNew.getUnitName().contains(StreetEnum.DA_YING_LU_STREET.getName()) ||
                    formSummaryNew.getUnitName().contains(StreetEnum.NMQ.getName())) &&
                    SqfwFormSummaryConstants.safety_check.equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                FireSafetyOnDayingRoadPdfDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), FireSafetyOnDayingRoadPdfDTO.class);
                String existDangerStr = pdfDTO.getExistDangerStr();

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getPlaceName());
                place.setLegalPerson(pdfDTO.getOperator());
                // 存在隐患
                if (StringUtils.isNotBlank(existDangerStr)) {
                    isHiddenNum ++;
                    String hidden = pdfDTO.getExistDangerStr().replaceAll("\\n", "");
                    place.setHidden(hidden);
                    list.add(place);
                } else {
                    place.setHidden("暂无隐患");
                    list.add(place);
                    noHiddenNum ++;
                }
            }

            // 白云区-安全排查
            if (formSummaryNew.getUnitName().contains(StreetEnum.BYU.getName()) &&
                    SupportBusinessTypeEnum.BATYUN_SAFE.getName().equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                // 数据准备
                ShawenTownSafetyPdfDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), ShawenTownSafetyPdfDTO.class);

                String existDangerStr = pdfDTO.getExistDangerStr();

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getAddress());
                place.setLegalPerson(pdfDTO.getOperator());
                // 存在隐患
                if (StringUtils.isNotBlank(existDangerStr)) {
                    isHiddenNum ++;
                    String hidden = pdfDTO.getExistDangerStr().replaceAll("\\n", "；");
                    place.setHidden(hidden);
                    list.add(place);
                } else {
                    place.setHidden("暂无隐患");
                    list.add(place);
                    noHiddenNum ++;
                }
            }

            // 观山湖-安全排查
            if (formSummaryNew.getUnitName().contains(StreetEnum.GSH.getName()) &&
                    SupportBusinessTypeEnum.SAFE_CHECK.getName().equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                // 数据准备
                SafeCheckTaskPdfDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), SafeCheckTaskPdfDTO.class);
                JSONObject jsonObject = JSON.parseObject(formSummaryNew.getParamData());
                JSONArray hiddenDanger = jsonObject.getJSONArray("hiddenDanger");
                JSONArray otherHiddenDangers = jsonObject.getJSONArray("otherHiddenDangers");
                if (hiddenDanger == null && otherHiddenDangers == null) continue;

                List<SqfwCustomForAdminCommonVO> bean = new ArrayList<>();
                for (int i = 0; i < hiddenDanger.size(); i ++) {
                    JSONObject json = hiddenDanger.getJSONObject(i);
                    String key = json.getString("key");
                    SqfwCustomForAdminCommonVO vo = new SqfwCustomForAdminCommonVO();
                    vo.setFlag(key);
                    vo.setCode(json.getString("riskCode"));
                    vo.setType(jsonObject.getString("type"));
                    bean.add(vo);
                }
                String existDangerStr = "";

                if (bean.size() > 0) {
                    Result<?> r = centuryCitySecurityForAdminController.getHiddenInfo(bean, formSummaryNew.getId());

                    existDangerStr = r.getData().toString();
                }

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getPlaceName());
                place.setLegalPerson(pdfDTO.getSiteManager());
                StringBuilder h = new StringBuilder();
                // 存在隐患
                if (StringUtils.isNotBlank(existDangerStr)) {
                    isHiddenNum ++;
                    String hs[] = existDangerStr.split("\\n");
                    for (int j = 0; j < hs.length; j ++) {
                        h.append(j+1).append("、").append(hs[j]).append("；");
                    }
                    place.setHidden(h.toString());
                    list.add(place);
                } else {
                    place.setHidden("暂无隐患");
                    list.add(place);
                    noHiddenNum ++;
                }
            }

            // 社会治安
            if (SqfwFormSummaryConstants.public_security.equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                // 大营路
                if (formSummaryNew.getUnitName().contains(StreetEnum.DA_YING_LU_STREET.getName())) {
                    PublicSecurityDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), PublicSecurityDTO.class);

                    WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                    place.setFillDate(formSummaryNew.getFillDate());
                    place.setName(pdfDTO.getPlaceName());
                    place.setLegalPerson(pdfDTO.getOperator());
                    // 存在隐患
                    if (pdfDTO.isWhetherThereIsAnyHiddenDanger()) {
                        isHiddenNum ++;
                        String hidden = pdfDTO.getRiskDescription();
                        place.setHidden(hidden);
                        list.add(place);
                    } else {
                        place.setHidden("暂无隐患");
                        list.add(place);
                        noHiddenNum ++;
                    }
                }
            }

            // 平安建设宣传 和 宣传排查
            if ((SupportBusinessTypeEnum.PROPAGANDA_OF_SAFE_CONSTRUCTION.getName().equals(type) ||
                    SqfwFormSummaryConstants.propaganda_screening.equals(type)) && type.equals(formSummaryNew.getType())) {
                total ++;

                try {
                    JSONObject jsonObject = JSON.parseObject(formSummaryNew.getParamData());
                    jsonObject.put("propagandaInvestigationAndSummary", null);//这个字段的内容会有问题，所以先设置为空
                    DuLaYingPropagandaOrScreeningPdfDTO pdfDTO = JSONObject.parseObject(jsonObject.toJSONString(), DuLaYingPropagandaOrScreeningPdfDTO.class);
                    WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                    place.setFillDate(formSummaryNew.getFillDate());
                    place.setName(pdfDTO.getAddress());
                    place.setType(pdfDTO.getType());
                    place.setTheme(pdfDTO.getTheme());
                    // 排查
                    if (PropagandaOrScreeningEnum.SCREENING.getName().equals(pdfDTO.getType())) {
                        List<ScreeningHiddenDTO> screeningHiddenList = pdfDTO.getScreeningHiddenList();
                        StringBuilder hidden = new StringBuilder();
                        int i = 1;
                        for (ScreeningHiddenDTO hiddenDTO : screeningHiddenList) {
                            if (hiddenDTO.getWhetherThereIsAnyHiddenDanger()) {
                                hidden.append(i).append("、").append(hiddenDTO.getOtherHiddenDangers()).append("；");
                                i ++;
                            }
                        }
                        isHiddenNum ++;
                        place.setHidden(hidden.length() == 0 ? "暂无隐患" : hidden.toString());
                        list.add(place);
                    } else {
                        place.setHidden("暂无隐患");
                        list.add(place);
                        noHiddenNum ++;
                    }
                } catch (Exception e) {
                    System.out.println("数据有误："+formSummaryNew.getParamData());
                }
            }

            // 养老服务站巡查
            if ((SupportBusinessTypeEnum.OLD_CARE_SERVICE.getName().equals(type) && type.equals(formSummaryNew.getType()))) {
                total ++;

                CenturyCityOldCarePdfDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), CenturyCityOldCarePdfDTO.class);

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getPlaceName());
            }

            // 关爱人员探访
            if ((SupportBusinessTypeEnum.CARE_WORKER_VISIT.getName().equals(type) && type.equals(formSummaryNew.getType()))) {
                total ++;

                CaringStaffDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), CaringStaffDTO.class);

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getName());
                place.setType(pdfDTO.getCareCategory());
            }

            // 儿童探访
            if (SupportBusinessTypeEnum.CHILDREN_VISITATION.getName().equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                ChildrenVisitationPdfDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), ChildrenVisitationPdfDTO.class);

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getVisitedName());
                place.setType(pdfDTO.getChildrenType());
            }

            // 脱贫家庭检测
            if (SupportBusinessTypeEnum.POVERTY_MONITORING.getName().equals(type) && type.equals(formSummaryNew.getType())) {
                total ++;

                PovertyAlleviationDTO pdfDTO = JSONObject.parseObject(formSummaryNew.getParamData(), PovertyAlleviationDTO.class);

                WorkSummaryDTO.Place place = new WorkSummaryDTO.Place();
                place.setFillDate(formSummaryNew.getFillDate());
                place.setName(pdfDTO.getName());
            }
        }

        dto.setType(type);
        dto.setTotal(total);
        dto.setIsHiddenNum(isHiddenNum);
        dto.setNoHiddenNum(noHiddenNum);
        dto.setList(list);

        return dto;
    }
}
